<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="css/animate.min.css">
    <style>
        header {
            height: 80px;
            background-color: rgb(138, 138, 138);
        }
        
        .container {
            width: 1200px;
            margin: 0 auto;
            border: 1px solid red
        }
        
        .p {
            height: 600px;
        }
        
        body {
            height: 2500px;
            margin: 0;
            padding: 0;
        }
        
        img.animated {
            animation-play-state: paused;
        }
        
        .running {
            animation-play-state: running !important;
        }
        
        .divp {
            width: 100px;
            height: 100px;
            background-color: red;
            position: absolute;
            top: 100px;
        }
    </style>
</head>

<body>
    <div class="divp"></div>
    <header>
        头部内容
    </header>
    <main class="container">
        <h2>主题</h2>
        <div class="p"></div>
        <div><button class="btn">点击动画开始</button></div>
        <img src="images/1.jpg" alt="" class="animated bounceIn ">
        <p>一段文字</p>
        <img src="images/2.jpg" alt="" class="animated bounceInRight ">
        <hr>
        <img src="images/3.jpg" alt="" class="animated zoomIn ">
    </main>
    <footer>
        <h2>脚步</h2>
    </footer>

    <script>
        var btn = document.querySelector('.btn');
        var animatedElement = document.querySelector('.animated')
            // btn.addEventListener('click', function() {
            //     animatedElement.classList.add("running")
            // })
            // window.addEventListener('scroll', function(e) {
            //     if (innerHeight - (animatedElement.offsetTop - scrollY) - animatedElement.offsetHeight > 200) {
            //         animatedElement.classList.add('running')
            //     }
            // })
            //获取所有动画元素
        var animatedElements = document.querySelectorAll('.animated');
        //窗口增加滚动条监听事件
        window.addEventListener('scroll', function(e) {
            //遍历每一个元素
            animatedElements.forEach(function(el) {
                if (innerHeight - (el.offsetTop - scrollY) - el.offsetHeight > 200) {
                    el.classList.add('running')
                }
            })

        })
    </script>
</body>

</html>